package com.ruoyi.web.controller.applet;


import com.ruoyi.applet.product.domain.ProductCategories;
import com.ruoyi.applet.product.service.IProductCategoriesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品分类Controller
 * @author ruoyi
 * @date 2024-11-20
 */
@Controller
@RequestMapping("/applet/productCategories")
public class ProductCategoriesController extends BaseController {
    
    private final String prefix = "applet/productCategories";
    
    @Resource
    private IProductCategoriesService productCategoriesService;
    
    @RequiresPermissions("applet:productCategories:view")
    @GetMapping()
    public String productCategories() {
        return prefix + "/productCategories";
    }
    
    /**
     * 查询产品分类列表
     */
    @RequiresPermissions("applet:productCategories:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductCategories productCategories) {
        startPage();
        List<ProductCategories> list = productCategoriesService.selectProductCategoriesList(productCategories);
        return getDataTable(list);
    }
    
    /**
     * 导出产品分类列表
     */
    @RequiresPermissions("applet:productCategories:export")
    @Log(title = "产品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductCategories productCategories) {
        List<ProductCategories> list = productCategoriesService.selectProductCategoriesList(productCategories);
        ExcelUtil<ProductCategories> util = new ExcelUtil<ProductCategories>(ProductCategories.class);
        return util.exportExcel(list, "产品分类数据");
    }
    
    /**
     * 新增产品分类
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存产品分类
     */
    @RequiresPermissions("applet:productCategories:add")
    @Log(title = "产品分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductCategories productCategories) {
        return toAjax(productCategoriesService.insertProductCategories(productCategories));
    }
    
    /**
     * 修改产品分类
     */
    @RequiresPermissions("applet:productCategories:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ProductCategories productCategories = productCategoriesService.selectProductCategoriesById(id);
        mmap.put("productCategories", productCategories);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存产品分类
     */
    @RequiresPermissions("applet:productCategories:edit")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductCategories productCategories) {
        return toAjax(productCategoriesService.updateProductCategories(productCategories));
    }
    
    /**
     * 删除产品分类
     */
    @RequiresPermissions("applet:productCategories:remove")
    @Log(title = "产品分类", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(productCategoriesService.deleteProductCategoriesByIds(ids));
    }
}
